import { copyFileSync, mkdirSync } from 'fs';
import { resolve, dirname } from 'path';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);

const rootDir = resolve(__dirname, '..');
const publicDir = resolve(rootDir, 'public');
const distDir = resolve(rootDir, 'dist');

// 确保目标目录存在
try {
  mkdirSync(distDir, { recursive: true });
} catch (err) {
  // 目录可能已经存在
}

// 复制文件
const filesToCopy = [
  'manifest.json',
  'sidepanel.html'
];

filesToCopy.forEach(file => {
  try {
    copyFileSync(
      resolve(publicDir, file),
      resolve(distDir, file)
    );
    console.log(`Copied ${file} to dist directory`);
  } catch (err) {
    console.error(`Failed to copy ${file}:`, err);
  }
}); 